package com.bw.ctroller;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.bw.service.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class Ctroller {
    @Autowired
    Service service;
    @RequestMapping("/qqq")
    public Object qqq(String nowDate){
        List<Map> qqq = service.qqq(nowDate);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONArray objects = new JSONArray();
        for (Map map : qqq) {
            JSONObject jsonObject1 = new JSONObject();
            jsonObject1.put("name",map.get("name"));
            jsonObject1.put("value",map.get("sum"));
            objects.add(jsonObject1);
        }

        jsonObject.put("data",objects);
        return jsonObject;
    }

    @RequestMapping("/www")
    public Object www(String nowDate) {
        List<Map> www = service.www(nowDate);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status", 0);
        jsonObject.put("msg", "");
        JSONObject jsonObject1 = new JSONObject();
        JSONArray objects = new JSONArray();
        for (Map map : www) {
            objects.add(map.get("name"));
        }
        JSONArray objects1 = new JSONArray();
        JSONObject jsonObject2 = new JSONObject();
        jsonObject2.put("name", "金额");
        JSONArray objects2 = new JSONArray();
        for (Map map : www) {
            objects2.add(map.get("sum"));
        }
        objects1.add(jsonObject2);
        jsonObject2.put("data", objects2);
        jsonObject1.put("categories", objects);
        jsonObject1.put("series", objects1);
        jsonObject.put("data", jsonObject1);
        return jsonObject;
        }

    @RequestMapping("/eeee")
    public Object eeee(String nowDate) {
        List<Map> eeee = service.eeee(nowDate);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status", 0);
        jsonObject.put("msg", "");
        jsonObject.put("data", eeee.get(0).get("sum"));
        return jsonObject;
    }
    }
